package com.example.indenture.order.dao;

import cn.hutool.db.sql.Order;
import com.example.indenture.common.vo.Search;
import com.example.indenture.order.entity.Orders;
import com.example.indenture.race.entity.Race;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface OrdersDao {

    //分页显示订单
    @Select("<script>"
            + "select * from orders "
            + "<where> "
            + "<if test='keyword != \"\" and keyword != null'>"
            + " and (name like '%${keyword}%') "
            + "</if>"
            + "</where>"
            + "<choose>"
            + "<when test='sort != \"\" and sort != null'>"
            + " Order by ${sort} ${direction}"
            + "</when>"
            + "<otherwise>"
            + " Order by id desc"
            + "</otherwise>"
            + "</choose>"
            + "</script>")
    List<Race> getAllOrders(Search search);

    //添加订单
    @Insert("insert into orders (create_date,update_time,alipay_no,order_id,pay_time,rid,state,tid,total,uid)" +
            "values(#{createDate},#{updateTime},#{alipayNo},#{orderId},#{payTime},#{rid},#{state},#{tid},#{total},#{uid})")
    Integer insert(Orders order);


    //更新支付编号

    //更新状态

    //更新支付时间
    @Update("update orders set update_time=#{updateTime},alipay_no=#{alipayNo},state=#{state},pay_time=#{payTime} where order_id=#{orderId}")
    Integer update(Orders order);

    //删除订单
    @Delete("delete from orders where order_id=#{orderId} ")
    Integer delete(Integer rid);

    @Select("select * from orders where order_id=#{orderId}")
    Orders selectOrderById(Integer orderId);
}
